import 'dart:io';

import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_svg/svg.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:hktk_app/dao/course_dao.dart';
import 'package:hktk_app/dao/industry_dao.dart';
import 'package:hktk_app/dao/my_dao.dart';
import 'package:hktk_app/dao/package_dao.dart';
import 'package:hktk_app/dialog/buy_dialog.dart';
import 'package:hktk_app/exception/dao_exception.dart';
import 'package:hktk_app/model/package/package_model.dart';
import 'package:hktk_app/pages/tab/study.dart';
import 'package:hktk_app/painter/triangle_painter.dart';
import 'package:hktk_app/util/buy_ios_util.dart';
import 'package:hktk_app/util/font_util.dart';
import 'package:hktk_app/util/my_util.dart';
import 'package:hktk_app/util/screen_adapter_helper.dart';
import 'package:hktk_app/util/toast_util.dart';
import 'package:hktk_app/util/view_util.dart';

class SelectPage extends StatefulWidget {
  final int initTabIndex;

  const SelectPage({Key? key, this.initTabIndex = 0}) : super(key: key);

  @override
  State<SelectPage> createState() => _SelectPageState();
}

class _SelectPageState extends State<SelectPage>
    with TickerProviderStateMixin, AutomaticKeepAliveClientMixin {
  final List<String> tips1 = ["考点点题", "考点vs视频", "助教实时答疑"];
  late TabController _tabController;
  late int _selectedTabIndex = 0;

  late List<dynamic> coursePackageList = [];
  late List<int> _selectedSkusIndex = [];

  late List questionBankList = [];
  late int _selectedPackageIndex = 0;
  late Map<String, dynamic> teacherPage = {
    "current": 1,
    "size": 3,
    "total": 0,
    "records": []
  };

  // late Future<dynamic> teacherPage;
  late bool _isLoading = true;
  late bool requestError = false;
  late double _computedPrice = 0;
  final typeMap = {
    0: [5],
    // 3: [1, 2, 3, 4],
    1: [1, 2, 3, 4],
  };
  final List<Map<String, dynamic>> items = [
    {"title": "章节练习", "subTitle": "享100%题量", "icon": "images/select/icon1.svg"},
    {"title": "模拟题", "subTitle": "全真模拟演练", "icon": "images/select/icon2.svg"},
    {"title": "历年真题", "subTitle": "全真模拟演练", "icon": "images/select/icon3.svg"},
    {"title": "每日一练", "subTitle": "每天5-10题", "icon": "images/select/icon4.svg"},
    {"title": "全真机考", "subTitle": "真实考试体验", "icon": "images/select/icon5.svg"},
    {"title": "文字解析", "subTitle": "答案解析", "icon": "images/select/icon6.svg"},
    {"title": "知识点V视频", "subTitle": "知识点视频", "icon": "images/select/icon7.svg"},
    {"title": "助教答疑", "subTitle": "高效服务", "icon": "images/select/icon8.svg"},
    {"title": "考前点题", "subTitle": "考前10天开放", "icon": "images/select/icon9.svg"},
    {"title": "章节真题", "subTitle": "章节真题", "png": "images/select/icon10.png"},
    {"title": "易错题", "subTitle": "大数据统计", "png": "images/select/icon11.png"},
    {"title": "模考大赛", "subTitle": "万人参赛", "png": "images/select/icon12.png"},
    {"title": "下载试卷", "subTitle": "下载打印", "png": "images/select/icon13.png"}
  ];

  @override
  void initState() {
    //   initState
    super.initState();
    _tabController =
        TabController(initialIndex: _selectedTabIndex, length: 2, vsync: this);
    //   初始化获取课程套餐，教师团队，品牌优势介绍(针对一个考试)？
    // 获取题库套餐（下拉选中），获取选中套餐详情

    Future.wait([
      PackageDao.listWithColumnType({
        "examId": IndustryDao.getExamKey().examId,
        "types": typeMap[0]!.join(","),
        "buying": "false"
      }).then((res) {
        coursePackageList = res;
      }),
      CourseDao.teacherList(current: 1, size: 3).then((res) {
        teacherPage = res;
      }),
      PackageDao.listWithColumnType({
        "examId": IndustryDao.getExamKey().examId,
        "types": typeMap[1]!.join(","),
        "buying": "false"
      }).then((res) {
        questionBankList = res;
        //  获取第一个套餐的详情
        if (questionBankList.isNotEmpty) {
          return PackageDao.packageSkuList(
                  packageId: questionBankList[_selectedPackageIndex]["id"])
              .then((res) {
            questionBankList[_selectedPackageIndex]["skuModels"] = res;
          });
        }
      })
    ]).then((value) {
      // 如果没有套餐，题库显示空数据防止错误
      if (mounted) {
        setState(() {
          requestError = false;
          _isLoading = false;
        });
      }
    }).catchError((err) {
      setState(() {
        requestError = true;
        _isLoading = false;
      });
    });
  }

  @override
  void dispose() {
    //   dispose
    super.dispose();
    _tabController.dispose();
  }

  /**
   * 如果没有任何题库套餐，则显示空数据
   * */
  Widget _possibleBankViewWidget() {
    if (questionBankList.isEmpty) {
      return Center(
        child: Text(
          "没有题库套餐",
          style: TextStyle(
            fontSize: 16,
            color: Colors.grey,
          ),
        ),
      );
    } else {
      return SingleChildScrollView(
        child: Column(crossAxisAlignment: CrossAxisAlignment.start, children: [
          Container(
            decoration: BoxDecoration(color: Colors.white),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
                Container(
                    width: 1.sw,
                    height: 230,
                    // height: 270,
                    padding: EdgeInsets.all(16),
                    decoration: BoxDecoration(
                      gradient: LinearGradient(
                        begin: Alignment.topCenter,
                        end: Alignment.bottomCenter,
                        colors: [Color(0xFF3D3D3D), Color(0xFF1D3156)],
                      ),
                    ),
                    child: Container(
                      decoration: BoxDecoration(
                        image: DecorationImage(
                          image: AssetImage("images/select/back1.png"),
                          fit: BoxFit.fitHeight,
                        ),
                      ),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Padding(
                            padding: EdgeInsets.only(top: 12, left: 8),
                            child: Text(
                              "会员",
                              style: TextStyle(color: Color(0xFFAA6F10)),
                            ),
                          ),
                          Container(
                            padding: EdgeInsets.only(left: 48),
                            margin: EdgeInsets.only(top: 24),
                            child: Text(
                              "通关必刷题库",
                              style: TextStyle(
                                  color: Color(0xFFAA6F10),
                                  fontSize: 20,
                                  fontWeight: FontWeight.bold),
                            ),
                          ),
                          Container(
                              margin: EdgeInsets.only(top: 30, left: 20),
                              width: 220,
                              child: Wrap(
                                runSpacing: 4,
                                spacing: 16,
                                children: [
                                  for (int i = 0; i < tips1.length; i++)
                                    SizedBox(
                                      width: 100,
                                      child: Row(
                                        children: [
                                          SvgPicture.asset(
                                            "images/select/little1.svg",
                                            width: 13,
                                          ),
                                          SizedBox(
                                            width: 4,
                                          ),
                                          Text(
                                            tips1[i],
                                            style: TextStyle(
                                                color: Color(0xFF966312),
                                                fontSize: 12),
                                          )
                                        ],
                                      ),
                                    )
                                ],
                              ))
                        ],
                      ),
                    )),
                Container(
                  margin: EdgeInsets.only(top: 20),
                  padding: EdgeInsets.symmetric(horizontal: 16),
                  child: Row(
                    mainAxisSize: MainAxisSize.max,
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Text("开通时长",
                              style: TextStyle(
                                  fontWeight: FontWeight.bold, fontSize: 20)),
                          Text(
                            "(有效期截止:${DateTime.now().add(Duration(days: (questionBankList[_selectedPackageIndex]["days"] as int) ?? 0)).toString().split(" ")[0]})",
                            style: TextStyle(
                                color: Color(0xFFB2B2B2), fontSize: 12),
                          )
                        ],
                      ),
                      DropdownButton(
                        value: _selectedPackageIndex,
                        items: [
                          for (var index = 0;
                              index < questionBankList.length;
                              index++)
                            DropdownMenuItem<int>(
                              value: index,
                              child: Text(questionBankList[index]["name"]),
                            ),
                        ],
                        onChanged: (int? value) {
                          _selectedPackageIndex = value!;
                          PackageDao.packageSkuList(
                                  packageId:
                                      questionBankList[_selectedPackageIndex]
                                          ["id"])
                              .then((res) {
                            if (mounted) {
                              setState(() {
                                questionBankList[_selectedPackageIndex]
                                    ["skuModels"] = res;
                                _selectedSkusIndex = [];
                                _computedPrice = 0;
                              });
                            }
                          });
                        },
                      )
                    ],
                  ),
                ),
                Container(
                    margin: EdgeInsets.only(top: 20, left: 16, right: 16),
                    padding: EdgeInsets.symmetric(vertical: 20, horizontal: 5),
                    decoration: BoxDecoration(
                        color: Color(0xFFF4FAFF),
                        borderRadius: BorderRadius.circular(10),
                        border: Border.all(width: 1, color: Color(0xFFCCE3EF))),
                    child: Row(
                      mainAxisAlignment: MainAxisAlignment.spaceBetween,
                      children: [
                        Text.rich(TextSpan(children: [
                          TextSpan(
                              text: "¥ ",
                              style: TextStyle(
                                  color: Color(0xFFF74E3A), fontSize: 20)),
                          TextSpan(
                              text: (questionBankList[_selectedPackageIndex]
                                          ["discountPrice"] /
                                      100)
                                  .toString(),
                              style: TextStyle(
                                  color: Color(0xFFF74E3A), fontSize: 24)),
                          TextSpan(
                              text: "/科",
                              style: TextStyle(color: Color(0xFF555555))),
                          WidgetSpan(
                            child: SizedBox(width: 12), // 自定义空格宽度
                          ),
                          TextSpan(
                              text:
                                  "有效期${questionBankList[_selectedPackageIndex]["days"]}日",
                              style: TextStyle(color: Color(0xFFB2B2B2))),
                        ])),
                        Text(
                          "${((questionBankList[_selectedPackageIndex]["discountPrice"] / 100) / (questionBankList[_selectedPackageIndex]["days"])).toStringAsFixed(2)}/天",
                          style: TextStyle(color: Color(0xFFF74E3A)),
                        )
                      ],
                    )),
                Container(
                  margin: EdgeInsets.only(top: 20),
                  padding: EdgeInsets.only(left: 15),
                  child: Text(
                    "考试科目",
                    style: TextStyle(fontSize: 18),
                  ),
                ),
                Padding(
                  padding: EdgeInsets.symmetric(horizontal: 16, vertical: 20),
                  child: Wrap(
                    spacing: 8,
                    runSpacing: 8,
                    children: [
                      for (var i = 0;
                          i <
                              questionBankList[_selectedPackageIndex]
                                      ["skuModels"]
                                  .length;
                          i++)
                        GestureDetector(
                          onTap: () {
                            setState(() {
                              if (!_selectedSkusIndex.contains(i)) {
                                _selectedSkusIndex.add(i);
                              } else {
                                _selectedSkusIndex.remove(i);
                              }
                              _computedPrice = _selectedSkusIndex
                                      .map((e) {
                                        return (questionBankList[
                                                _selectedPackageIndex]
                                            ["skuModels"] as List)[e];
                                      })
                                      .toList()
                                      .fold(0, (a, b) {
                                        return (a + b.discountPrice!) as int;
                                      }) /
                                  100;
                            });
                          },
                          child: Container(
                            padding: EdgeInsets.symmetric(
                                horizontal: 10, vertical: 2),
                            decoration: BoxDecoration(
                                border: Border.all(
                                  color: _selectedSkusIndex.contains(i)
                                      ? Color(0xFFFF9FA6)
                                      : Color(0xFFF6F6F6),
                                ),
                                borderRadius: BorderRadius.circular(10),
                                color: _selectedSkusIndex.contains(i)
                                    ? Color(0xFFFFF4F4)
                                    : Color(0xFFF6F6F6)),
                            child: Text(
                              questionBankList[_selectedPackageIndex]
                                          ["skuModels"]?[i]
                                      .name ??
                                  "",
                              style: TextStyle(
                                  color: _selectedSkusIndex.contains(i)
                                      ? Color(0xFFE6494E)
                                      : Color(0xFF555555)),
                            ),
                          ),
                        ),
                    ],
                  ),
                ),
              ],
            ),
          ),
          Container(
            margin: EdgeInsets.only(top: 14),
            padding: EdgeInsets.all(16),
            decoration: BoxDecoration(color: Colors.white),
            child: Column(
              children: [
                Row(
                  children: [
                    Text(
                      "会员权益",
                      style: TextStyle(fontSize: 18),
                    ),
                    SizedBox(
                      width: 16,
                    ),
                    //   图片
                    Container(
                      width: 110,
                      height: 37,
                      padding: EdgeInsets.only(left: 40, top: 8),
                      decoration: BoxDecoration(
                        image: DecorationImage(
                          image: AssetImage("images/select/icon_2.png"),
                          fit: BoxFit.cover,
                        ),
                      ),
                      child: Text(
                        "14+权益",
                        style: TextStyle(fontSize: 12),
                      ),
                    )
                  ],
                ),
                Wrap(
                  spacing: 10,
                  runSpacing: 10,
                  children: [
                    for (var item in items)
                      SizedBox(
                        width: 100,
                        child: Column(
                          spacing: 2,
                          children: [
                            if (item.containsKey("icon"))
                              SvgPicture.asset(
                                item["icon"],
                                width: 46,
                              )
                            else
                              Image.asset(
                                item["png"],
                                width: 46,
                              ),
                            Text(
                              item["title"],
                              style: TextStyle(fontSize: 14),
                            ),
                            Text(item["subTitle"],
                                style: TextStyle(
                                    fontSize: 10, color: Color(0xFFB2B2B2))),
                          ],
                        ),
                      )
                  ],
                )
              ],
            ),
          ),
          Container(
            margin: EdgeInsets.only(left: 16, right: 16, top: 30, bottom: 15),
            child: Column(
              crossAxisAlignment: CrossAxisAlignment.start,
              spacing: 10,
              children: [
                Container(
                  padding:
                      EdgeInsets.only(left: 20, right: 3, top: 3, bottom: 3),
                  decoration: BoxDecoration(
                    color: Color(0xFF21242D),
                    borderRadius: BorderRadius.circular(30),
                  ),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    mainAxisSize: MainAxisSize.max,
                    children: [
                      Column(
                        crossAxisAlignment: CrossAxisAlignment.start,
                        children: [
                          Row(
                            children: [
                              Text(
                                "￥ $_computedPrice",
                                style: TextStyle(
                                    color: Color(0xFFF7B04C), fontSize: 16),
                              ),
                              SizedBox(width: 10),
                              Text("已选${_selectedSkusIndex.length}科",
                                  style: TextStyle(
                                      color: Color(0xFFB2B2B2), fontSize: 12)),
                              SizedBox(width: 3),
                              Text(
                                  "${questionBankList[_selectedPackageIndex]["days"]}天",
                                  style: TextStyle(
                                      color: Color(0xFFB2B2B2), fontSize: 12)),
                            ],
                          ),
                          Row(
                            children: [
                              Text(
                                "原价￥${questionBankList[_selectedPackageIndex]["discountPrice"] / 100}",
                                style: TextStyle(
                                    decoration: TextDecoration.lineThrough,
                                    color: Color(0xFFC4BEB6),
                                    decorationColor: Color(0xFFC4BEB6),
                                    fontSize: 12),
                              )
                            ],
                          )
                        ],
                      ),
                      Container(
                        decoration: BoxDecoration(
                          gradient: LinearGradient(
                            begin: Alignment.centerLeft,
                            end: Alignment.centerRight,
                            colors: [Color(0xFFE2AE65), Color(0xFFEBCE5B)],
                          ),
                          borderRadius: BorderRadius.circular(30),
                        ),
                        child: TextButton(
                            onPressed: () async {
                              // 判断是否是游客
                              if (visitorMode()) {
                                showDialog(
                                    context: context,
                                    builder: (BuildContext context1) {
                                      return AlertDialog(
                                          title: Text("提示"),
                                          content: Text("请先登录"),
                                          actions: [
                                            TextButton(
                                                onPressed: () {
                                                  Navigator.of(context1).pop();
                                                },
                                                child: Text("取消")),
                                            TextButton(
                                                onPressed: () {
                                                  Navigator.pop(context1);
                                                  Navigator
                                                      .pushNamedAndRemoveUntil(
                                                          context,
                                                          "/login",
                                                          (route) => false);
                                                },
                                                child: Text("确定"))
                                          ]);
                                    });

                                return;
                              }

                              //   创建订单
                              //   前往订单支付  页

                              final List<SkuModel> selected =
                                  _selectedSkusIndex.map((e) {
                                return (questionBankList[_selectedPackageIndex]
                                    ["skuModels"][e] as SkuModel);
                              }).toList();

                              if (selected.isEmpty) {
                                ToastUtil.show(context: context, msg: "请选择科目");
                                return;
                              }

                              var payHide = await MyDao.versionCurrentIos();
                              final List<String> skuIds =
                                  selected.map((e) => e.id!).toList();
                              PackageDao.createOrder(skuIds: skuIds)
                                  .then((res) {
                                final List skuModels =
                                    questionBankList[_selectedPackageIndex]
                                        ["skuModels"];
                                try {
                                  questionBankList[_selectedPackageIndex]
                                      ["skuModels"] = skuModels.map((e) {
                                    return (e as SkuModel).toJson();
                                  }).toList();
                                  if (mounted) {
                                    // pop返回skuModels变为Map，未恢复
                                    Navigator.pushNamed(context, "/order/pay",
                                        arguments: {
                                          "package": PackageModel.fromJson(
                                              questionBankList[
                                                  _selectedPackageIndex]),
                                          "index": 0,
                                          "price": _computedPrice,
                                          "iosPrice": BuyIOSUtil.getIosPrice(
                                              _computedPrice),
                                          "payHide": payHide,
                                          "skuList": selected,
                                          "orderModel": res
                                        }).then((v) {
                                      questionBankList[_selectedPackageIndex]
                                          ["skuModels"] = skuModels;
                                    });
                                  }
                                } catch (e) {
                                  questionBankList[_selectedPackageIndex]
                                      ["skuModels"] = skuModels;
                                }
                              }).catchError((e) {
                                if (mounted) {
                                  String str = "未知错误，请重试";
                                  if (e is DaoException) {
                                    str = e.msg;
                                    // str = "请选择";
                                  }
                                  ToastUtil.show(context: context, msg: str);
                                }
                              });
                            },
                            child: Text(
                              "立即购买",
                              style: TextStyle(
                                  fontSize: 18,
                                  height: 1.5,
                                  color: Color(0xFF664006)),
                            )),
                      ),
                    ],
                  ),
                ),
                Text(
                  "购买提示:题库属虚拟不提供退款服务，敬请谅解",
                  style: TextStyle(fontSize: 12, color: Color(0xFFFF9D00)),
                )
              ],
            ),
          )
        ]),
      );
    }
  }

  // 根据请求响应的结果，可能有不同的情况
  Widget _possibleWidget() {
    if (_isLoading) {
      return Center(
        child: CircularProgressIndicator(),
      );
    } else {
      if (requestError) {
        return Center(
          child: Text("请求失败，请稍后再试"),
        );
      } else {
        return Column(
          children: [
            // 弹出弹框，根据当前tab，二级级联科目、栏目
            GestureDetector(
              onTap: () {
                // Navigator.pushNamed(context, "/select-exam");
                // showModalBottomSheet(context: context, builder: builder)
              },
              child: Padding(
                  padding: EdgeInsets.only(left: 16, right: 16),
                  child: Row(
                    mainAxisSize: MainAxisSize.max,
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Text(
                        IndustryDao.getExamKey().examName,
                        style: FontUtil.fontBlack1(16,
                            fontWeight: FontWeight.w500),
                      ),
                      hiSpace(width: 8),
                      CustomPaint(
                        painter: TrianglePainter(),
                      )
                    ],
                  )),
            ),
            Row(
              mainAxisAlignment: MainAxisAlignment.start,
              mainAxisSize: MainAxisSize.max,
              children: [
                Container(
                  alignment: Alignment.centerLeft,
                  height: 48,
                  width: 0.4.sw,
                  child: TabBar(
                      controller: _tabController,
                      tabAlignment: TabAlignment.fill,
                      labelColor: Colors.black,
                      dividerHeight: 0,
                      indicator: GradientUnderlineTabIndicator(
                        colors: [Color(0xFF3C6CFF), Color(0xFFE5EBFF)], // 渐变色
                        lineHeight: 3.0, // 下划线高度
                        // borderRadius: BorderRadius.circular(22.0.w), // 圆角
                      ),
                      tabs: [
                        Tab(
                          child: Text("课程"),
                        ),
                        Tab(
                          child: Text("题库"),
                        ),
                      ]),
                ),
              ],
            ),
            SizedBox(
              height: 1.sh -
                  ScreenUtil().statusBarHeight -
                  48 -
                  ScreenHelper.bottomNavigationBarHeight -
                  10 -
                  25,
              child: TabBarView(
                  controller: _tabController,
                  physics: NeverScrollableScrollPhysics(),
                  children: [
                    SingleChildScrollView(
                      child: Column(
                          crossAxisAlignment: CrossAxisAlignment.start,
                          children: [
                            Container(
                              margin: EdgeInsets.only(top: 8),
                              width: 1.sw,
                              decoration: BoxDecoration(
                                  color: Colors.white,
                                  borderRadius: BorderRadius.circular(10)),
                              child: Padding(
                                  padding: EdgeInsets.all(16),
                                  child: Column(
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      spacing: 14,
                                      children: [
                                        Text(
                                          "组合班级",
                                          style: TextStyle(fontSize: 18),
                                        ),
                                        for (var item in coursePackageList)
                                          Row(
                                            crossAxisAlignment:
                                                CrossAxisAlignment.start,
                                            children: [
                                              Image.asset(
                                                "images/test/2.jpg",
                                                width: 150.0.w,
                                                height: 150.0.w,
                                              ),
                                              Expanded(
                                                  child: Padding(
                                                      padding: EdgeInsets.only(
                                                          left: 5,
                                                          top: 5,
                                                          bottom: 5),
                                                      child: Column(
                                                        crossAxisAlignment:
                                                            CrossAxisAlignment
                                                                .start,
                                                        spacing: 10,
                                                        mainAxisAlignment:
                                                            MainAxisAlignment
                                                                .start,
                                                        children: [
                                                          Text(item["name"]),
                                                          // 如果有介绍备注
                                                          if (item["remark"] !=
                                                                  null &&
                                                              item["remark"] !=
                                                                  "")
                                                            HtmlWidget(
                                                                item["remark"]),
                                                          Wrap(
                                                            spacing: 10,
                                                            runSpacing: 5,
                                                            children: [
                                                              // tagNameList可能为null，非数组格式
                                                              if (item[
                                                                      "tagNameList"] !=
                                                                  null)
                                                                for (var i = 0;
                                                                    i <
                                                                        item["tagNameList"]
                                                                            .length;
                                                                    i++)
                                                                  Container(
                                                                    padding:
                                                                        EdgeInsets
                                                                            .all(5),
                                                                    decoration: BoxDecoration(
                                                                        color: Color(
                                                                            0xFFFFF2E1),
                                                                        borderRadius:
                                                                            BorderRadius.circular(8)),
                                                                    child: Text(
                                                                      item["tagNameList"]
                                                                          [i],
                                                                    ),
                                                                  ),
                                                            ],
                                                          ),
                                                          Row(
                                                            crossAxisAlignment:
                                                                CrossAxisAlignment
                                                                    .center,
                                                            mainAxisAlignment:
                                                                MainAxisAlignment
                                                                    .spaceBetween,
                                                            children: [
                                                              Container(
                                                                  width:
                                                                      78.76.w,
                                                                  height: 24.h,
                                                                  padding: EdgeInsets
                                                                      .only(
                                                                          left:
                                                                              2),
                                                                  decoration:
                                                                      BoxDecoration(
                                                                    image: DecorationImage(
                                                                        image: AssetImage(
                                                                            "images/test/3.png"),
                                                                        fit: BoxFit
                                                                            .cover),
                                                                  ),
                                                                  child: Align(
                                                                    alignment:
                                                                        Alignment
                                                                            .centerLeft,
                                                                    child: Text(
                                                                      "折扣价: ${item["discountPrice"] / 100}",
                                                                      style: TextStyle(
                                                                          color: Colors
                                                                              .white,
                                                                          fontSize:
                                                                              10.sp),
                                                                    ),
                                                                  )),
                                                            ],
                                                          ),
                                                          Row(
                                                            mainAxisSize:
                                                                MainAxisSize
                                                                    .max,
                                                            mainAxisAlignment:
                                                                MainAxisAlignment
                                                                    .spaceBetween,
                                                            children: [
                                                              Text.rich(
                                                                TextSpan(
                                                                  style: DefaultTextStyle.of(
                                                                          context)
                                                                      .style,
                                                                  children: [
                                                                    TextSpan(
                                                                        text:
                                                                            '￥${item["discountPrice"] / 100}',
                                                                        style:
                                                                            TextStyle(
                                                                          color:
                                                                              Color(0xFFF64E3A),
                                                                          fontSize:
                                                                              18,
                                                                          fontWeight:
                                                                              FontWeight.w500,
                                                                          letterSpacing:
                                                                              0.40,
                                                                        )),
                                                                    TextSpan(
                                                                        text:
                                                                            '\n原价:${item["price"] / 100}',
                                                                        style: TextStyle(
                                                                            decoration:
                                                                                TextDecoration.lineThrough)),
                                                                  ],
                                                                ),
                                                              ),
                                                              Padding(
                                                                padding: EdgeInsets
                                                                    .only(
                                                                        right:
                                                                            0),
                                                                child:
                                                                    Container(
                                                                  height: 22,
                                                                  padding: const EdgeInsets
                                                                      .symmetric(
                                                                      horizontal:
                                                                          10,
                                                                      vertical:
                                                                          2),
                                                                  decoration:
                                                                      ShapeDecoration(
                                                                    color: Color(
                                                                        0xFF3C6CFF),
                                                                    shape:
                                                                        RoundedRectangleBorder(
                                                                      borderRadius:
                                                                          BorderRadius.circular(
                                                                              90),
                                                                    ),
                                                                  ),
                                                                  alignment:
                                                                      Alignment
                                                                          .center,
                                                                  child:
                                                                      GestureDetector(
                                                                          onTap:
                                                                              () {
                                                                            // 前往详情页
                                                                            // Navigator.pushNamed(context, "/course-package-detail");
                                                                            //
                                                                            // return;

                                                                            var height =
                                                                                ScreenUtil().screenHeight;
                                                                            double
                                                                                sheetHeight =
                                                                                height * 0.8;
                                                                            () async {
                                                                              bool flag = await MyDao.versionCurrentIos();

                                                                              if (mounted) {
                                                                                // 弹出层
                                                                                showModalBottomSheet(
                                                                                  context: context,
                                                                                  // 设置底部弹出框全屏显示
                                                                                  isScrollControlled: true,
                                                                                  // 自定义弹出层高度
                                                                                  constraints: BoxConstraints(maxHeight: sheetHeight),
                                                                                  // 自定义圆角
                                                                                  shape: RoundedRectangleBorder(
                                                                                    borderRadius: BorderRadius.only(
                                                                                      topLeft: Radius.circular(24),
                                                                                      topRight: Radius.circular(24),
                                                                                    ),
                                                                                  ),
                                                                                  builder: (BuildContext context) {
                                                                                    return BuyDialog(
                                                                                      package: PackageModel.fromJson(item),
                                                                                      index: 0,
                                                                                      payHide: flag,
                                                                                    );
                                                                                  },
                                                                                );
                                                                              }
                                                                            }();
                                                                          },
                                                                          child:
                                                                              Text(
                                                                            '立即领取',
                                                                            style:
                                                                                TextStyle(
                                                                              color: Colors.white,
                                                                              fontSize: 12,
                                                                              fontWeight: FontWeight.w400,
                                                                              letterSpacing: 0.12,
                                                                            ),
                                                                          )),
                                                                ),
                                                              )
                                                            ],
                                                          )
                                                        ],
                                                      )))
                                            ],
                                          )
                                      ])),
                            ),
                            // 如果没有老师，则不展示
                            Container(
                              margin: EdgeInsets.only(top: 20),
                              padding: EdgeInsets.only(top: 16),
                              decoration: BoxDecoration(
                                  borderRadius: BorderRadius.circular(10),
                                  color: Colors.white),
                              child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  spacing: 10,
                                  children: [
                                    Padding(
                                      padding:
                                          EdgeInsets.only(left: 16, right: 16),
                                      child: Text(
                                        "教研团队",
                                        style: TextStyle(fontSize: 18),
                                      ),
                                    ),
                                    Container(
                                      width: 1.sw,
                                      padding:
                                          EdgeInsets.only(left: 16, right: 16),
                                      child: SingleChildScrollView(
                                        scrollDirection: Axis.horizontal,
                                        child: Row(
                                          spacing: 10,
                                          children: [
                                            for (int i = 0;
                                                i <
                                                    (teacherPage["records"]
                                                            as List)
                                                        .length;
                                                i++)
                                              Container(
                                                height: 240,
                                                width: 200,
                                                decoration: ShapeDecoration(
                                                  image: DecorationImage(
                                                    image: AssetImage(
                                                        "images/home/teacher_background.png"),
                                                    fit: BoxFit.fill,
                                                  ),
                                                  shape: RoundedRectangleBorder(
                                                      borderRadius:
                                                          BorderRadius.circular(
                                                              4)),
                                                ),
                                                child: Stack(
                                                  children: [
                                                    Positioned(
                                                        left: 10,
                                                        child: Image.asset(
                                                          "images/test/1.png",
                                                          width: 120,
                                                        )),
                                                    Column(
                                                      children: [
                                                        Container(
                                                          height: 110,
                                                          padding:
                                                              EdgeInsets.only(
                                                                  left: 14,
                                                                  right: 14,
                                                                  top: 14),
                                                          child: Row(
                                                              mainAxisSize:
                                                                  MainAxisSize
                                                                      .max,
                                                              mainAxisAlignment:
                                                                  MainAxisAlignment
                                                                      .spaceBetween,
                                                              crossAxisAlignment:
                                                                  CrossAxisAlignment
                                                                      .start,
                                                              children: [
                                                                SizedBox(
                                                                  height: 60,
                                                                  child: Text(
                                                                    teacherPage["records"][i]
                                                                            [
                                                                            "teacherName"]
                                                                        .split(
                                                                            '')
                                                                        .join(
                                                                            '\n'),
                                                                    style: TextStyle(
                                                                        fontSize:
                                                                            12,
                                                                        overflow:
                                                                            TextOverflow.ellipsis),
                                                                  ),
                                                                ),
                                                                Image.asset(
                                                                  "images/select/icon_1.png",
                                                                  width: 48,
                                                                )
                                                              ]),
                                                        ),
                                                        Container(
                                                          height: 130,
                                                          width: 200,
                                                          padding:
                                                              EdgeInsets.only(
                                                                  top: 12,
                                                                  left: 30,
                                                                  right: 12,
                                                                  bottom: 12),
                                                          decoration:
                                                              BoxDecoration(
                                                                  color: Color(
                                                                      0xFFF4FAFF)),
                                                          child: Text(teacherPage[
                                                                  "records"][i]
                                                              ["introduce"]),
                                                        )
                                                      ],
                                                    )
                                                  ],
                                                ),
                                              )
                                          ],
                                        ),
                                      ),
                                    )
                                  ]),
                            ),
                            // Text("图片介绍")
                          ]),
                    ),
                    _possibleBankViewWidget()
                  ]),
            )
          ],
        );
      }
    }
    return Container();
  }

  @override
  Widget build(BuildContext context) {
    super.build(context);
    // 
    return SafeArea(
        child: Padding(
            padding: EdgeInsets.only(top: 10), child: _possibleWidget()));
  }

  @override
  //   wantKeepAlive
  bool get wantKeepAlive => true;
}
